import Config from './config.js'

export default {
	onAuthorization() {
		var url = encodeURIComponent(window.location.href.split('#')[0]);
		var uid = getnavivalues()['uid'];
		if (!isExist(uid)) {
			window.location.href = 'https://www.homeeyes.cn/wx/Com_oauth?targetUrl=' + url;
		} else {
			return uid;
		}
	},
	/**
	 * 获取参数
	 */
	getnavivalues() {
		var url = window.location.search; //获取url中"?"符后的字串
		url = url.split('#/')[0];
		var theRequest = new Array();
		if (url.indexOf('?') !== -1) {
			var str = url.substr(1);
			var strs = str.split('&');
			for (var i = 0; i < strs.length; i++) {
				theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1]);
			}
		}
		return theRequest;
	}
	/**
	 * 显示toast
	 */
	,
	showAlert(msg, type = 0, confirm) {
		let icon = 'none';
		if (type == 1) {
			icon = 'success';
		} else if (type == 2) {
			icon = 'loading';
		}
		uni.showToast({
			title: msg,
			icon: icon,
			mask: true,
			duration: 1000
		});
		setTimeout(function() {
			uni.hideToast();
			if (confirm) {
				confirm();
			}
		}, 1000);
	}
	/**
	 * 提示模态窗
	 */
	,
	showModalMsg(msg = '你有一条新的提示信息', confirmMsg = '确定', cancelMsg = '取消', confirm, cancel) {
		uni.showModal({
			title: '提示',
			content: msg,
			confirmText: confirmMsg,
			cancelText: cancelMsg,
			success: function(res) {
				if (res.confirm) {
					if (confirm) {
						confirm(res.confirm);
					}
				} else if (res.cancel) {
					if (cancel) {
						cancel(res.cancel);
					}
				}
			}
		});
	}
	/**
	 * @param {Object} time 时间戳 如果时间戳为10位则转换为13位
	 */
	,
	getNowFormatDate(time) {
		if (time.length == 10) {
			time *= 1000;
		}
		var date = new Date(time);
		var seperator1 = '-';
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		if (month >= 1 && month <= 9) {
			month = '0' + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = '0' + strDate;
		}
		var currentdate = year + seperator1 + month + seperator1 + strDate;
		return currentdate;
	}
	/**
	 * 获取今天时间
	 * type 获取时间类型 1 字符串   2数组
	 * 默认为1
	 */
	,
	getTodayDate(type = 1) {
		var date = new Date();
		var seperator1 = '-';
		var seperator2 = ':';
		var year = date.getFullYear();
		var month = date.getMonth() + 1;
		var strDate = date.getDate();
		var hhstr = date.getHours();
		var mmStr = date.getMinutes();
		var ssStr = date.getSeconds();
		if (month >= 1 && month <= 9) {
			month = '0' + month;
		}
		if (strDate >= 0 && strDate <= 9) {
			strDate = '0' + strDate;
		}
		if (hhstr >= 0 && hhstr <= 9) {
			hhstr = '0' + hhstr;
		}
		if (mmStr >= 0 && mmStr <= 9) {
			mmStr = '0' + mmStr;
		}
		if (ssStr >= 0 && ssStr <= 9) {
			ssStr = '0' + ssStr;
		}
		if (type == 1) {
			return (year + seperator1 + month + seperator1 + strDate + ' ' + hhstr + seperator2 + mmStr + seperator2 + ssStr);
		} else {
			return [year, month, strDate, hhstr, mmStr, ssStr];
		}
	}
	/**
	 * 判断是否为微信客户端
	 */
	,
	isWinXin() {
		var isWeiXin = navigator.userAgent.toLowerCase().indexOf('micromessenger') > -1 ? true : false;
		return isWeiXin;
	}
	/**
	 * 是否存在字符
	 * @param {Object} value
	 */
	,
	isExist(value) {
		if (value !== null && value !== undefined && value.length > 0) {
			return true;
		} else {
			return false;
		}
	}
	/**
	 * 是否存在数字
	 * @param {Object} value
	 */
	,
	isNumberExist(value) {
		if (value !== null && value !== undefined && value.length > 0 && parseInt(value) > 0) {
			return true;
		} else {
			return false;
		}
	},
	clickCallPhone(phone) {
		if (isExist(phone) && phone.length >= 8) {
			var content = '是否拨打电话：' + phone;
			uni.showModal({
				title: '提示',
				content: content,
				success: function(res) {
					if (res.confirm) {
						uni.makePhoneCall({
							phoneNumber: phone //仅为示例
						});
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		} else {
			uni.showToast({
				title: '未有联系方式',
				duration: 1000,
				icon: 'none'
			});
			setTimeout(function() {
				uni.hideToast();
			}, 1000);
		}
	}
	/**
	 * 获取月份天数
	 * @param {Object} month
	 */
	,
	getDateDays(month) {
		var date = new Date();
		var year = date.getFullYear();
		if (month == 0) {
			month = date.getMonth() + 1;
		}
		var d = new Date(year, month, 0);
		return d.getDate();
	}
	/**
	 * 获取当前月份
	 */
	,
	getDateMonth() {
		var date = new Date();
		var month = date.getMonth() + 1;
		return month;
	},
	randomCoding() {
		var result = [];
		//生成一个0到25的数字
		var ranNum = Math.ceil(Math.random() * 25);
		//大写字母'A'的ASCII是65,A~Z的ASCII码就是65 + 0~25;
		//然后调用String.fromCharCode()传入ASCII值返回相应的字符并push进数组里
		result.push(String.fromCharCode(65 + ranNum));
		return result.join('');
	}
	/**
	 * 加密
	 * @param {Object} data
	 */
	,
	bitEncrypt(data) {
		var data = data || '';
		var arr = data.split('');
		var result = arr.map(function(item) {
			let letter = randomCoding();
			return item + letter;
		});
		return result.join('');
	}
	/**
	 * 解密
	 * @param {Object} data
	 */
	,
	encEncrypt(data) {
		var arr = data.split('');
		let result = '';
		for (let i = 0, len = arr.length; i < len; i++) {
			if (i % 2 == 0) {
				result += arr[i];
			}
		}
		return result;
	}
	/**
	 * 获取分享配置
	 * @param {Object} params
	 */
	,
	getSharePage(params) {
		var pages = getCurrentPages(); //获取加载的页面
		var currentPage = pages[pages.length - 1]; //获取当前页面的对象
		var url = currentPage.route + "?" + params;
		let shareinfo = {
			title: '都市之佳',
			desc: '邀请您体验小程序',
			path: url,
			logo: 'https://www.homeeyes.cn/app/images/icon_logo.png'
		}
		return shareinfo;
	},
	getSharePage2(params, name, desc, logo) {
		var pages = getCurrentPages(); //获取加载的页面
		var currentPage = pages[pages.length - 1]; //获取当前页面的对象
		var url = currentPage.route + "?" + params;
		let shareinfo = {
			title: name,
			desc: desc,
			path: url,
			logo: logo
		}
		return shareinfo;
	},
	friendlyDate(timestamp) {
		var formats = {
			'year': '%n% 年前',
			'month': '%n% 月前',
			'day': '%n% 天前',
			'hour': '%n% 小时前',
			'minute': '%n% 分钟前',
			'second': '%n% 秒前',
		};
	
		var now = Date.now();
		var seconds = Math.floor((now - timestamp) / 1000);
		var minutes = Math.floor(seconds / 60);
		var hours = Math.floor(minutes / 60);
		var days = Math.floor(hours / 24);
		var months = Math.floor(days / 30);
		var years = Math.floor(months / 12);
	
		var diffType = '';
		var diffValue = 0;
		if (years > 0) {
			diffType = 'year';
			diffValue = years;
		} else {
			if (months > 0) {
				diffType = 'month';
				diffValue = months;
			} else {
				if (days > 0) {
					diffType = 'day';
					diffValue = days;
				} else {
					if (hours > 0) {
						diffType = 'hour';
						diffValue = hours;
					} else {
						if (minutes > 0) {
							diffType = 'minute';
							diffValue = minutes;
						} else {
							diffType = 'second';
							diffValue = seconds === 0 ? (seconds = 1) : seconds;
						}
					}
				}
			}
		}
		return formats[diffType].replace('%n%', diffValue);
	},
	formatTime(time) {
		if (typeof time !== 'number' || time < 0) {
			return time
		}
	
		var hour = parseInt(time / 3600)
		time = time % 3600
		var minute = parseInt(time / 60)
		time = time % 60
		var second = time
	
		return ([hour, minute, second]).map(function(n) {
			n = n.toString()
			return n[1] ? n : '0' + n
		}).join(':')
	}
	
	,
	formatLocation(longitude, latitude) {
		if (typeof longitude === 'string' && typeof latitude === 'string') {
			longitude = parseFloat(longitude)
			latitude = parseFloat(latitude)
		}
	
		longitude = longitude.toFixed(2)
		latitude = latitude.toFixed(2)
	
		return {
			longitude: longitude.toString().split('.'),
			latitude: latitude.toString().split('.')
		}
	},
	UNITS: {
		'年': 31557600000,
		'月': 2629800000,
		'天': 86400000,
		'小时': 3600000,
		'分钟': 60000,
		'秒': 1000
	},
	humanize(milliseconds) {
		var humanize = '';
		for (var key in this.UNITS) {
			if (milliseconds >= this.UNITS[key]) {
				humanize = Math.floor(milliseconds / this.UNITS[key]) + key + '前';
				break;
			}
		}
		return humanize || '刚刚';
	},
	format(dateStr) {
		var date = this.parse(dateStr)
		var diff = Date.now() - date.getTime();
		if (diff < this.UNITS['天']) {
			return this.humanize(diff);
		}
		var _format = function(number) {
			return (number < 10 ? ('0' + number) : number);
		};
		return date.getFullYear() + '/' + _format(date.getMonth() + 1) + '/' + _format(date.getDay()) + '-' +
			_format(date.getHours()) + ':' + _format(date.getMinutes());
	},
	parse(str) { //将"yyyy-mm-dd HH:MM:ss"格式的字符串，转化为一个Date对象
		var a = str.split(/[^0-9]/);
		return new Date(a[0], a[1] - 1, a[2], a[3], a[4], a[5]);
	},
	showDialog(msg = '操作异常,请稍后重试', confirmMsg = '确定', confirm) {
		uni.showModal({
			title: '提示',
			content: msg,
			showCancel: false,
			confirmText: confirmMsg,
			success: function(res) {
				if (confirm) {
					confirm(res.confirm);
				}
			}
		});
	},
	authOther(appid, back_url) {
		let redirect_url = Config.prodUrl + '/api/wechat/open_authorize/back_url/' + encodeURIComponent(back_url) + '/token/' +
			localStorage.getItem("token");
		let component_appid = 'wx97ceaa52cccedd78'
		let uri = encodeURIComponent(redirect_url);
		let authURL =
			`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_userinfo&state=STATE&component_appid=${component_appid}#wechat_redirect`;
		location.href = authURL;
	},
	authMe(back_url) {
		let redirect_url = Config.baseUrl + 'api/wechatauth/index?back_url=' + encodeURIComponent(back_url);
		let appid = "wxaccb99362d4e0e4f";
		let authURL =
			`https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_url}&response_type=code&scope=snsapi_userinfo&state=e54c849337a8948c5bbe0553bc9878e6&connect_redirect=1#wechat_redirect`;
		location.href = authURL;
	},
	getIdentity(mode, site_id) {
		if (site_id > 0) {
			if (mode == 0) {
				return "DIY_VIEW_RANDOM_1601348600"
			} else if (mode == 1) {
				return "DIY_VIEW_RANDOM_1601347552"
			} else if (mode == 2) {
				return "DIY_VIEW_RANDOM_1600162329"
			} else {
				//商店生成模板
				return "DIYVIEW_SHOP_INDEX"
			}

		} else {
			//默认官方平台
			return "DIYVIEW_INDEX"
		}

	},
	/**
	 * 页面跳转
	 * @param {string} to 跳转链接 /pages/idnex/index
	 * @param {Object} param 参数 {key : value, ...}
	 * @param {string} mode 模式 
	 */
	redirectTo(to, param, mode) {
		let url = to;

		if (param != undefined) {
			Object.keys(param).forEach(function(key) {
				if (url.indexOf('?') != -1) {
					url += "&" + key + "=" + param[key];
				} else {
					url += "?" + key + "=" + param[key];
				}
			});
		}
		if (url.indexOf('tag=') == -1) {
			if (url.indexOf('?') != -1) {
				url += '&tag=' + uni.getStorageSync('shoptag');
			} else {
				url += '?tag=' + uni.getStorageSync('shoptag');
			}
		}

		switch (mode) {
			case 'tabbar':
				// 跳转到 tabBar 页面，并关闭其他所有非 tabBar 页面。
				uni.switchTab({
					url: url
				})
				break;
			case 'redirectTo':
				// 关闭当前页面，跳转到应用内的某个页面。
				uni.redirectTo({
					url: url
				});
				break;
			case 'reLaunch':
				// 关闭所有页面，打开到应用内的某个页面。
				uni.reLaunch({
					url: url
				});
				break;
			default:
				// 保留当前页面，跳转到应用内的某个页面
				uni.navigateTo({
					url: url
				});
		}
	},
	/**
	 * 图片路径转换
	 * @param {String} img_path 图片地址
	 * @param {Object} params 参数，针对商品、相册里面的图片区分大中小，size: big、mid、small
	 */
	img(img_path, params) {
		var path = "";
		if (img_path != undefined && img_path != "") {
			if (params && img_path != this.getDefaultImage().default_goods_img) {
				// 过滤默认图
				let arr = img_path.split(".");
				let suffix = arr[arr.length - 1];
				arr.pop();
				arr[arr.length - 1] = arr[arr.length - 1] + "_" + params.size;
				arr.push(suffix);
				img_path = arr.join(".");
			}
			if (img_path.indexOf("http://") == -1 && img_path.indexOf("https://") == -1) {
				path = Config.imgDomain + "/" + img_path;
			} else {
				path = img_path;
			}
			if (path.indexOf("http://") != -1) {
				path = path.replace("http:", "https:")
			}
		}
		return path;
	},
	/**
	 * 图片路径转换
	 * @param {String} img_path 图片地址
	 * @param {Object} params 参数，针对商品、相册里面的图片区分大中小，size: big、mid、small
	 */
	imgs(img_path) {
		var path = "";
		if (img_path != undefined && img_path != "") {

			if (img_path.indexOf("http://") == -1 && img_path.indexOf("https://") == -1) {
				path = Config.h5Domain + '/' + img_path;
			} else {
				path = img_path;
			}
			if (path.indexOf("http://") != -1) {
				path = path.replace("http:", "https:")
			}
		}

		return path;
	},
	/**
	 * 时间戳转日期格式
	 * @param {Object} timeStamp
	 */
	timeStampTurnTime(timeStamp) {
		if (timeStamp != undefined && timeStamp != "" && timeStamp > 0) {
			var date = new Date();
			date.setTime(timeStamp * 1000);
			var y = date.getFullYear();
			var m = date.getMonth() + 1;
			m = m < 10 ? ('0' + m) : m;
			var d = date.getDate();
			d = d < 10 ? ('0' + d) : d;
			var h = date.getHours();
			h = h < 10 ? ('0' + h) : h;
			var minute = date.getMinutes();
			var second = date.getSeconds();
			minute = minute < 10 ? ('0' + minute) : minute;
			second = second < 10 ? ('0' + second) : second;
			return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;
		} else {
			return "";
		}
	},
	/**
	 * 倒计时
	 * @param {Object} seconds 秒
	 */
	countDown(seconds) {
		let [day, hour, minute, second] = [0, 0, 0, 0]
		if (seconds > 0) {
			day = Math.floor(seconds / (60 * 60 * 24))
			hour = Math.floor(seconds / (60 * 60)) - (day * 24)
			minute = Math.floor(seconds / 60) - (day * 24 * 60) - (hour * 60)
			second = Math.floor(seconds) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60)
		}
		if (day < 10) {
			// day = '0' + day
		}
		if (hour < 10) {
			// hour = '0' + hour
		}
		if (minute < 10) {
			// minute = '0' + minute
		}
		if (second < 10) {
			// second = '0' + second
		}
		return {
			d: day,
			h: hour,
			i: minute,
			s: second
		};
	},
	/**
	 * 数值去重
	 * @param {Array} arr 数组
	 * @param {string} field 字段
	 */
	unique(arr, field) {
		const res = new Map();
		return arr.filter((a) => !res.has(a[field]) && res.set(a[field], 1));
	},
	/**
	 * 判断值是否在数组中
	 * @param {Object} elem
	 * @param {Object} arr
	 * @param {Object} i
	 */
	inArray: function(elem, arr) {
		return arr == null ? -1 : arr.indexOf(elem);
	},
	/**
	 * 获取某天日期
	 * @param {Object} day
	 */
	getDay: function(day) {
		var today = new Date();
		var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
		today.setTime(targetday_milliseconds);

		const doHandleMonth = function(month) {
			var m = month;
			if (month.toString().length == 1) {
				m = "0" + month;
			}
			return m
		}

		var tYear = today.getFullYear();
		var tMonth = today.getMonth();
		var tDate = today.getDate();
		var tWeek = today.getDay();
		var time = parseInt(today.getTime() / 1000);
		tMonth = doHandleMonth(tMonth + 1);
		tDate = doHandleMonth(tDate);

		const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
		return {
			't': time,
			'y': tYear,
			'm': tMonth,
			'd': tDate,
			'w': week[tWeek]
		};
	},
	/**
	 * 图片选择加上传
	 * @param number num
	 * @param {Object} params
	 * @param {Object} callback
	 * return array
	 */
	upload: function(num, params, callback) {
		var data = {
			token: uni.getStorageSync('token'),
			private_key: Config.privateKey
		}
		data = Object.assign(data, params);
		var imgs_num = num;
		var _self = this;
		uni.chooseImage({
			count: imgs_num,
			sizeType: ['compressed'], //可以指定是原图还是压缩图，默认二者都有
			sourceType: ['album', 'camera'], //从相册或者拍照
			success: async function(res) {
				const tempFilePaths = res.tempFilePaths;

				// typeof callback == 'function' && callback(tempFilePaths);

				var _data = data;
				var imgs = [];
				for (var i = 0; i < tempFilePaths.length; i++) {
					var path = await _self.upload_file_server(tempFilePaths[i], _data, params.path);
					imgs.push(path);
				}
				typeof callback == 'function' && callback(imgs);
			}
		});
	},
	//上传
	upload_file_server(tempFilePath, data, path) {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: Config.baseUrl + '/api/upload/' + path,
				filePath: tempFilePath,
				name: 'file',
				formData: data,
				success: function(res) {
					var path_str = JSON.parse(res.data);
					if (path_str.code >= 0) {
						resolve(path_str.data.pic_path);
					} else {
						reject("error");
					}
				}
			});

		});

	},
	/**
	 * 复制
	 * @param {Object} message
	 * @param {Object} callback
	 */
	copy(value, callback) {
		// #ifdef H5
		var oInput = document.createElement('input'); //创建一个隐藏input（重要！）
		oInput.value = value; //赋值
		document.body.appendChild(oInput);
		oInput.select(); // 选择对象
		document.execCommand("Copy"); // 执行浏览器复制命令
		oInput.className = 'oInput';
		oInput.style.display = 'none';
		this.showToast({
			title: '复制成功'
		});
		typeof callback == 'function' && callback();
		// #endif

		// #ifdef MP || APP-PLUS
		uni.setClipboardData({
			data: value,
			success: () => {
				typeof callback == 'function' && callback();
			}
		});
		// #endif
	},
	/**
	 * 是否是微信浏览器
	 */
	isWeiXin() {
		// #ifndef H5
		return false;
		// #endif
		var ua = navigator.userAgent.toLowerCase();
		if (ua.match(/MicroMessenger/i) == "micromessenger") {
			return true;
		} else {
			return false;
		}
	},

	/**
	 * 显示消息提示框
	 *  @param {Object} params 参数
	 */
	showToast(params = {}) {
		params.title = params.title || "";
		params.icon = params.icon || "none";
		params.position = params.position || 'bottom';
		uni.showToast(params);
	},
	/**
	 * 显示消息确定框
	 *  @param {Object} params 参数
	 */
	showModal(params = {}) {
		params.title = params.title || "";
		params.content = params.content || "";
		params.cancelText = params.cancelText || "取消";
		params.confirmText = params.confirmText || "确定";
		uni.showModal(params);
	},
	/**
	 * 检测苹果X以上的手机
	 */
	isIPhoneX() {
		let res = uni.getSystemInfoSync();
		if (res.model && res.model.search('iPhone X') != -1) {
			return true;
		}
		return false;
	},
	/**
	 * 深度拷贝对象
	 * @param {Object} obj
	 */
	deepClone(obj) {
		const isObject = function(obj) {
			return typeof obj == 'object';
		}

		if (!isObject(obj)) {
			throw new Error('obj 不是一个对象！')
		}
		//判断传进来的是对象还是数组
		let isArray = Array.isArray(obj)
		let cloneObj = isArray ? [] : {}
		//通过for...in来拷贝
		for (let key in obj) {
			cloneObj[key] = isObject(obj[key]) ? this.deepClone(obj[key]) : obj[key]
		}
		return cloneObj
	},
	refreshBottomNav() {
		var bottomNav = uni.getStorageSync("bottom_nav");
		bottomNav = JSON.parse(bottomNav);
		for (var i = 0; i < bottomNav.list.length; i++) {
			var item = bottomNav.list[i];
			var obj = {
				index: i
			};
			obj.text = item.title;
			obj.iconPath = this.img(item.iconPath);
			obj.selectedIconPath = this.img(item.selectedIconPath);
			if (bottomNav.type == 1) {
				// 图文
			} else if (bottomNav.type == 2) {
				// 图片
			} else if (bottomNav.type == 3) {
				// 文字
			}
			uni.setTabBarItem(obj);
		}
	},
	/**
	 * 自定义模板的跳转链接
	 * @param {Object} link
	 */
	diyRedirectTo(link, method) {
		if (link == null || link == '' || !link.wap_url) return;
		if (link.wap_url.indexOf('http') != -1) {
			this.redirectTo('/otherpages/web/web?src=' + link.wap_url);
		} else {
			if (link.site_id) {
				this.redirectTo(link.wap_url, {
					site_id: link.site_id
				});
			} else {
				this.redirectTo(link.wap_url);
			}
		}
	},
	/**
	 * 获取默认图
	 * @param {Object} link
	 */
	getDefaultImage() {
		let defaultImg = uni.getStorageSync('default_img');
		if (defaultImg) {
			defaultImg = JSON.parse(defaultImg);
			defaultImg.default_goods_img = Config.h5Domain + defaultImg.default_goods_img;
			defaultImg.default_headimg = Config.h5Domain + defaultImg.default_headimg;
			defaultImg.default_shop_img = Config.h5Domain + defaultImg.default_shop_img;
			return defaultImg;
		} else {
			return {
				default_goods_img: '',
				default_headimg: '',
				default_shop_img: ''
			};
		}
	},

	/**
	 * 判断手机是否为iphoneX系列
	 */
	uniappIsIPhoneX() {
		let isIphoneX = false;
		let systemInfo = uni.getSystemInfoSync();
		// #ifdef MP || APP-PLUS
		if (systemInfo.model.search('iPhone X') != -1) {
			isIphoneX = true;
		}
		// #endif

		// #ifdef H5
		var u = navigator.userAgent;
		var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
		if (isIOS) {
			if (systemInfo.screenWidth == 375 && systemInfo.screenHeight == 812 && systemInfo.pixelRatio == 3) {
				isIphoneX = true;
			} else if (systemInfo.screenWidth == 414 && systemInfo.screenHeight == 896 && systemInfo.pixelRatio == 3) {
				isIphoneX = true;
			} else if (systemInfo.screenWidth == 414 && systemInfo.screenHeight == 896 && systemInfo.pixelRatio == 2) {
				isIphoneX = true;
			}
		}
		// #endif
		return isIphoneX;
	},
	/**
	 * 判断手机是否为iphoneX系列   	判断当前页面栈是否存在，如果存在，则返回该页面栈，否则跳转到该页面
	 */
	jumpPage(url) {
		let jump = true;
		let arr = getCurrentPages().reverse();
		for (let i = 0; i < arr.length; i++) {
			if (url.indexOf(arr[i].route) != -1) {
				jump = false;
				uni.navigateBack({
					delta: i
				});
				break;
			}
		}
		if (jump) {
			this.$util.diyRedirectTo(url);
		}
	},

	// 自定义返回事件
	goBack() {
		if (getCurrentPages().length > 1) {
			uni.navigateBack()
		} else {
			uni.navigateTo({
				url: '/pages/index/index/index'
			})
		}
	},
	getQueryVariable(variable) {
		var query = location.hash.substring(1);
		//console.log(window.location);
		var vars = query.split("&");
		for (var i = 0; i < vars.length; i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
		return '';
	},
	isExist(value) {
		if (value !== null && value !== undefined && value !== "undefined" && value !== "null" && value.length > 0) {
			return true;
		} else {
			return false;
		}
	},
	isDevice() {
		//js判断当前移动设备平台
		if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
			return 'ios';
		} else if (/(Android)/i.test(navigator.userAgent)) {
			return 'android';
		} else if (/(Windows Phone)/i.test(navigator.userAgent)) {
			return 'windows';
		}
	}
}
